package com.eupmt.lab3.controllers.impl;

import com.eupmt.lab3.controllers.IProducteController;
import com.eupmt.lab3.domain.Article;
import com.eupmt.lab3.domain.Distribuidor;
import com.eupmt.lab3.domain.Producte;
import com.eupmt.lab3.persistence.ibatis.dao.ProducteDaoManager;
import com.eupmt.lab3.utils.Log;

/**
 *
 * @author dondiaaa
 */
public class ProducteController implements IProducteController {

    //Atributes
    protected static ProducteController instance = null;
    ProducteDaoManager dao = null;
    private Log log = null;

    //Constructors
    private ProducteController() {
        log = new Log();
    }

    //Methods
    public void saveProducte(Producte prod) throws Exception {
        dao = ProducteDaoManager.getInstance();
        dao.saveProducte(prod);
    }

    public void insertProducte(Producte prod) throws Exception {
        dao = ProducteDaoManager.getInstance();
        dao.insertProducte(prod);
    }

    public void updateProducte(Producte prod) throws Exception {
        dao = ProducteDaoManager.getInstance();
        dao.updateProducte(prod);
    }

    public void deleteProducte(Producte prod) throws Exception {
        dao = ProducteDaoManager.getInstance();
        dao.deleteProducte(prod);
    }

    public Producte getProducteById(int idProducte) throws Exception {
       dao = ProducteDaoManager.getInstance();
       return dao.getProducteById(idProducte);
    }

    public Producte getProducteByNumSerie(String numserie) throws Exception {
        dao = ProducteDaoManager.getInstance();
        return dao.getProducteByNom(numserie);
    }

    public Producte getProducteByArticle(Article article) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Producte getProducteByDistribuidor(Distribuidor distribuidor) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    // Patró Singleton
    public static ProducteController getInstance() {
        if (instance == null) {
            instance = new ProducteController();
        }
        return instance;
    }
}
